<template>
  <div class="app-container">
  <!--站点数据-->
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="时间" prop="time">
        <el-date-picker
          v-model="queryParams.time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="userList">
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="name" width="110px" />
      <el-table-column label="手机号" align="center" prop="tel" width="110px" />
      <el-table-column label="申请代理城市" align="center" prop="city" />
      <el-table-column label="申请代理区县" align="center" prop="qx" />
      <el-table-column label="申请代理区域" align="center" prop="qy" />
      <el-table-column label="申请开通区域" align="center" prop="ktqy" width="130px" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
        
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详细 -->
    <el-dialog title="详细" :visible.sync="detailOpen" width="600px">
      <el-form ref="form" :model="form" label-width="120px" size="mini">
        <el-row>
          <el-col :span="8">
            <el-form-item label="历史发单数：">{{ form.totalCount }}</el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态：">{{ cuserState(form.status) }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="姓名：">{{ form.name }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="微信昵称：">{{ form.nickName }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="手机号：">{{ form.mobile }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="绑定微信：">{{ form.openId }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="年龄：">{{ form.age }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="性别：">{{ form.sex === '0' ? '男':'女' }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="所属校区：">{{ form.schoolName }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="注册时间：">{{ form.createTime }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="最后一次登录时间：">{{ form.lastLoginTime }}</el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="最后一次发单时间：">{{ form.lastIssueTime }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailOpen = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listProxy } from "@/api/pt/proxy.js";
export default {
  name: "proxy",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 已有校区所在城市数据
      ownCity: [],
      // 已有校区数据
      schoolOptions: [],
      // 城市数据
      cityOptions: [],
      // 表单参数
      form: {
      },
      //详情打开
      detailOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        time: [new Date(Date.now() - 7 * 24 * 60 * 60 * 1000), new Date()],
        name: undefined,
        status: undefined,
        schoolId: undefined,
        mobile: undefined
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "站点名称不能为空", trigger: "blur" }
        ],
        schoolId: [
          { required: true, message: "请选择校区", trigger: "blur" }
        ],
        address: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ],
        time: [
          { required: true, message: "请选择时间", trigger: "blur" },
        ],
        email: [
          { required: true, message: "邮箱地址不能为空", trigger: "blur" },
          {
            type: "email",
            message: "'请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        phone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /* 用户状态 */
    cuserState(str){
      if(str === 0) {
        return '正常'
      }else if(str === 1) {
        return '冻结中'
      }else if(str === 2) {
        return '已拉黑'
      }else if(str === 3) {
        return '已注销'
      }
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listProxy(this.addDateRange2(this.queryParams)).then(response => {
          this.userList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
      this.form = {
        id: undefined,
        schoolId: undefined,
        name: undefined,
        city: undefined,
        status: undefined,
        address: undefined,
        siteDescribe: undefined,
        personInCharge: undefined,
        mobile: undefined,
        personInCharge2: undefined,
        mobile2: undefined,
        time: undefined,
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row, type) {
      this.title = "修改";
      row.time = [new Date(row.startTime),new Date(row.endTime)]
      this.form = row
      if(type === '详情') {
        this.detailOpen = true;
      }else {
        this.open = true;
      }
    },
  }
};
</script>

<style type="text/css">
  .dian {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    background: #999;
    margin-right: 6px;
  }
</style>
